package com.aldobucchi.core.dependency
{
	import mx.core.IMXMLObject;
	import mx.core.UIComponent;
	
	import com.aldobucchi.utils.App;




	/**
	 * 
	 * Adds dependency management to a base MXML object implementation.
	 * Updates are disabled until initialized is called by the layout manager.
	 * If you use this object in AS3 the initialized() method will not get called automatically, so
	 * you must call manuallyInitialized() in order to activate the automatic updates
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */
	public class MXMLObjectWithDependenciesBase extends EventDispatcherWithDependenciesBase implements IMXMLObject
	{




		
		//////////////////////////////////////
		// document
		//////////////////////////////////////
		
		private var _document:UIComponent;
		
		public function get document( ):UIComponent
		{
			return _document;
		}


		//////////////////////////////////////
		// id
		//////////////////////////////////////

		private var _id:String;
		
		public function get id( ):String
		{
			return _id;
		}




		private var initCalled:Boolean = false;

		
		public function MXMLObjectWithDependenciesBase( )
		{
			dh.autoUpdateFlag.disable( );		
		}

		
		
		
		/**
		 * 
		 * If you happen to use this object in AS3 ( not mxml )
		 * then initialized will not get called automatically.
		 * Call this function manually or otherwise the autoupdates will remain disabled forever
		 * 
		 */		
		public function manuallyInitialized( ):void
		{
			init( );		
		}
		


		private function init( ):void
		{
			if( initCalled )
				return;
				
			dh.autoUpdateFlag.enable( );
			
			initCalled = true;
			
		}


		
		public function initialized( document:Object, id:String ):void
		{
			_document = document as UIComponent;
			_id = id;
			
			init( );			
		}
		
	}
}